package org.itboys.mongodb.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.itboys.commons.utils.time.TimeUtils;
import org.mongodb.morphia.annotations.Id;

import java.io.Serializable;
import java.util.Date;


/**
 * 作者：jiangxiong
 * 日期：2017年2月8日
 * 联系方式 ：empty90911@126.com
 * 描述：mongo实体基类，只支持ID为Long类型
 * 
 */
public class BaseMongoEntity implements Serializable {
	//Id

	private static final long serialVersionUID = -564576529547142626L;

	@Id
	private long id;
    private Long creator;//数据创建者ID
 //   private String creatorName;//数据创建者昵称
	@JsonIgnore
	private long ct;//创建时间的毫秒long类型。只存储，不输出。实际输出，createTime(年月日，时分秒)和createDate(年月日)
	@JsonIgnore
	private long ut;//修改时间的毫秒long类型。只存储，不输出。实际输出，updateTime(年月日，时分秒)和updateDate(年月日)

    private Long updater;//数据最后修改者ID。
   
   // private String updaterName;//数据最后修改者昵称。

    private Integer isDeleted= 0;//是否删除标识。0.否，1是
	//获取创建时间-(年月日，时分秒)
	public String getCreateTime() {

		return TimeUtils.format(new Date(ct),"yyyy-MM-dd HH:mm:ss");
	}
	//获取创建时间-(年月日)
	public String getCreateDate() {
		return TimeUtils.format(new Date(ct),"yyyy-MM-dd");
	}
	//获取修改时间-(年月日，时分秒)
	public String getUpdateTime() {

		return TimeUtils.format(new Date(ut),"yyyy-MM-dd HH:mm:ss");
	}
	//获取修改-(年月日)
	public String getUpdateDate() {
		return TimeUtils.format(new Date(ut),"yyyy-MM-dd");
	}



	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Long getCreator() {
		return creator;
	}

	public void setCreator(Long creator) {
		this.creator = creator;
	}

	/*public String getCreatorName() {
		return creatorName;
	}

	public void setCreatorName(String creatorName) {
		this.creatorName = creatorName;
	}*/

	public long getCt() {
		return ct;
	}

	public void setCt(long ct) {
		this.ct = ct;
	}

	public long getUt() {
		return ut;
	}

	public void setUt(long ut) {
		this.ut = ut;
	}

	public Long getUpdater() {
		return updater;
	}

	public void setUpdater(Long updater) {
		this.updater = updater;
	}

/*	public String getUpdaterName() {
		return updaterName;
	}

	public void setUpdaterName(String updaterName) {
		this.updaterName = updaterName;
	}*/

	public Integer getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(Integer isDeleted) {
		this.isDeleted = isDeleted;
	}

	public boolean equals(Object obj){
		if(obj==null){
			return false;
		}
		if(this.getId()==0L){
			return false;
		}
		if (obj.getClass().equals(this.getClass()) && (obj instanceof BaseLongIdEntity)) {
			BaseLongIdEntity o = (BaseLongIdEntity)obj;
			if(o.getId()==0L){
				return false;
			}
			return o.getId()==this.id;
		}
		return false;
	}

	public String toString(){
		return ToStringBuilder.reflectionToString(this);
	}

	public int hashCode(){
		return HashCodeBuilder.reflectionHashCode(this);
	}
} 
